import { constantRoutes, asyncRoutes } from '@/router'
const state = {
  routes: constantRoutes // 路由表 默认静态路由
}
const mutations = {
  setRoutes(state, newRoutes) {
    state.routes = [...constantRoutes, ...newRoutes]
  }
}
const actions = {
  filterRoutes(context, menus) { // 权限标识
    const routes = [] // 当前用户拥有的动态路由权限
    menus.forEach(key => {
      routes.push(...asyncRoutes.filter(item => item.name === key)) // 找出对应的路由规则
    })
    context.commit('setRoutes', routes)
    return routes
  }
}
export default {
  namespaced: true,
  state,
  mutations,
  actions
}
